import React, { useState } from "react";
import { Upload } from "../../component";
import { message } from "antd";
import axios from "axios";
const Index = () => {
	const [url, setUrl] = useState('')
  const beforeUpload = (file: File) => {
    if (!file.type.includes("image")) {
      message.error("上传的只可以是图片");
      return false;
    }
    return true;
  };
	const upload = async (file: File) => {
		const formData = new FormData();
		formData.append('chunk', file, file.name);
		const resp = await axios.post('/upload/oss', formData);
		console.log(resp.data)
		setUrl(resp.data.data.url)
	}
  return (
    <div>
      <Upload beforeUpload={beforeUpload} upload={ upload }>
        <button>上传到阿里云</button>
      </Upload>
			{
				url && <img src={url} alt="" width={300} height={300}/>
			}
    </div>
  );
};

export default Index;
